define(["jquery", "easy-admin"], function ($, ea) {
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'supplier.OrderTaking/index',

        export_url: 'supplier.OrderTaking/export',
        import_url: 'supplier.OrderTaking/import',

        batch_shipment: 'supplier.OrderTaking/batch_shipment',
        batch_export: 'supplier.OrderTaking/batch_export',
        batch_take_order: 'supplier.OrderTaking/batch_take_order',
        batch_discard_order: 'supplier.OrderTaking/batch_discard_order',

        detail: 'supplier.OrderTaking/detail',
        distribute: 'supplier.OrderTaking/distribute',
        cancel: 'supplier.OrderTaking/cancel',
        get: 'supplier.OrderTaking/get_order',

    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,

                toolbar: ['refresh',
                    [{
                        text: '生成出货单',
                        url: init.batch_shipment,
                        method: 'open',
                        auth: 'batch_shipment',
                        class: 'layui-btn layui-btn-primary layui-border-blue  layui-btn-sm',
                        icon: 'fa fa-window-restore ',
                        extend: 'data-checkbox = "true"',

                    }],
                    [{
                        text: '批量导出',
                        url: init.batch_export,
                        method: 'request',
                        auth: 'export',
                        class: 'layui-btn layui-btn-sm',
                        icon: 'fa fa-upload ',
                        extend: 'data-url="' + init.batch_export + '"',

                    }],
                    [{
                        text: '批量接单',
                        url: init.batch_take_order,
                        method: 'request',
                        auth: 'batch_take_order',
                        class: 'layui-btn layui-btn-normal layui-btn-sm',
                        icon: 'fa fa-cloud-download ',
                        extend: 'data-checkbox = "true"',

                    }],
                    [{
                        text: '批量拒单',
                        url: init.batch_discard_order,
                        method: 'request',
                        auth: 'batch_discard_order',
                        class: 'layui-btn layui-btn-danger layui-btn-sm',
                        icon: 'fa fa-ban text-danger',
                        extend: 'data-checkbox = "true"',

                    }],

                ],
                height: 750,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'sales_number', search: 'batch', title: '订单号', minWidth: 80},

                    {field: 'sku', title: 'SKU', search: 'batch'},
                    {
                        field: 'rule.name', title: '规则',
                        selectList: ea.getSelectList('Rule', 'name'),
                        selectAttribute: 'lay-search', searchOp: '=', minWidth: 80
                    },
                    {field: 'productMaps.item_number', search: 'batch', title: '工厂货号', minWidth: 80},

                    {field: 'unique_code', search: 'batch', title: '唯一码', filter: true, sort: false},


                    {
                        field: 'category.name', title: '产品类别',
                        selectList: ea.getSelectList('Category', 'name'),
                        selectAttribute: 'lay-search', searchOp: '='
                        , width: 80,
                    },

                    {
                        field: 'status', title: '产品状态', width: 100,
                        selectList: {
                            '已派单': '已派单',
                            '已接单': '已接单',
                            '已拒单': '已拒单',
                            '已出货': '已出货',
                            '已收货': '已收货',
                            '异常单': '异常单',
                            '未合格': '未合格',
                            '返修中': '返修中',
                            '已完成': '已完成',
                            '取消出货': '取消出货',
                        }
                    },
                    {
                        field: 'ai_status', title: 'AI状态', width: 100,
                        selectList: {
                            'AI已制作': 'AI已制作',
                            'AI取消单': 'AI取消单',
                            '工厂接单': '工厂接单',
                            '工厂异常': '工厂异常',
                        }
                    },


                    {field: 'send_time', title: '派单时间', search: 'range', minWidth: 80},
                    {field: 'give_time', title: '要求入库时间', search: 'range', minWidth: 80},
                    {
                        field: 'is_overtime',
                        search: false,
                        title: '是否超时',
                        width: 100,
                        selectList: {0: '未超时', 1: '超时'},
                        templet: ea.table.list
                    },


                    {
                        title: '操作',
                        templet: '#barDemo',
                    }

                ]],
                customDefaultToolbar: true,
                defaultToolbar: [
                    {
                        title: '搜索',
                        layEvent: 'TABLE_SEARCH',
                        icon: 'layui-icon-search',
                        extend: 'data-table-id="' + init.table_render_id + '"'
                    }
                ],

                filter: {
                    items: ['column'],
                    cache: true,
                    bottom: false
                }, done: function () {
                    //穿透 回调 外面的this
                    layui.use(["soulTable"], soulTable => {
                        soulTable.render(this);
                    });
                }
            });
            ea.listen();
            ea.table.showSearch(true);
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },

        detail: function () {
            ea.listen();
        },
        get_order: function () {

            ea.listen();
        },
        cancel: function () {
            ea.listen();
        },
        batch_shipment: function () {
            ea.listen();
        },

    };
    return Controller;
});